var prefix = ctx + "/system/commonreportstatistics";
var params = {
	page : 1,
	limit : 10,

	sort : "id",
	order : "desc"
};
var keyValue = getQueryString("sid");
$(document).ready(function() {
	var width = $(window).width();
	$("#div_body").css("width", width - 10);

	if (keyValue != "") {
		ExecutClick(true);
		 
		 
	} else {
		getNames();
	}

});

function getNames() {
	GridStrative = get_info_list_one(ctx
			+ "/system/commonreportstatistics/listAllName?type=1");// 网格区域代码
	var html = "<option value=''>--请选择--</option>"
	$.each(GridStrative, function(i, n) {
		html += "<option value='" + n.SID + "'>" + n.SNAME + "</option>"
	});
	$("#sname").html(html);
}

// 刷新页面
function reload() {
	window.location.reload();
}

// 查询按钮
function ExecutClick(historyOrNot) {
	var sid = "";
	if (keyValue == "") {

		sid = $("#sname").val();
		
		
	} else {

		sid = keyValue;
	}

	$
			.ajax({
				type : "get",
				url : prefix + "/getReport",
				data : {
					sid : sid,
					StartTime : $("#begdate").val(),
					EndTime : $("#enddate").val(),
					HistoryOrNo : historyOrNot
				},
				async : false,
				success : function(data) {

					$("#tashow").html("");

					var showtable = "<table class='hovertable'>";

					$
							.each(
									data,
									function(index, item) {

										if (index == 0) {
											showtable += "<tr>";
											$.each(item, function(_key) {
												// console.log(_key);
												showtable += "<th>" + _key
														+ "</th>"; // 拼接：表格标题

											});
											showtable += "</tr>";
										}
										showtable += "<tr onmouseover=\"this.style.backgroundColor='#ffff66';\" onmouseout=\"this.style.backgroundColor='#d4e3e5';\">";
										$.each(item, function(_key) {

											if (item[_key] == null) {
												item[_key] = "-"
											}
											showtable += "<td>" + item[_key]
													+ "</td>"; // 拼接：表格内容
										});
										showtable += "</tr>";

									});
					showtable += "</table>";
					// $("#tashow").html(showtable);

					document.getElementById("tashow").innerHTML = showtable;

				},
				error : function(XMLHttpRequest, textStatus, errorThrown) {
					alert(XMLHttpRequest.status);
					alert(XMLHttpRequest.readyState);
					alert(textStatus);
				}
			});
}

// 获取所需要的信息
function get_info_list_one(url) {
	var dictinoaryList = [];
	$.ajax({
		type : "Get",
		url : url,
		contentType : "application/json; charset=utf-8",
		data : {
			limit : 10000,
			offset : 0,
		},
		dataType : "json",
		async : false,
		error : function(request) {
			parent.layer.alert("获取字典列表失败！请检查!");
		},
		success : function(data) {
			dictinoaryList = data;
		}
	});
	return dictinoaryList;
}